<script setup lang="ts" name="ApiErrorLogDetail">
import { DICT_TYPE } from '@/enums/dictEnums'
import { formatDate } from '@/utils/dateUtil'
import type { ApiErrorLogType } from '@/api/infra/apiLog/error'

const { t } = useI18n() // 国际化
const visible = ref(false) // 弹窗的是否展示
const detailData = ref({} as ApiErrorLogType) // 详情数据

/** 打开弹窗 */
const open = async (data: ApiErrorLogType) => {
  visible.value = true
  detailData.value = data
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<template>
  <Dialog v-model="visible" :title="t('common', 'detail')" type="scroll" width="800px" height="500px">
    <el-descriptions :column="1" border>
      <el-descriptions-item :label="t('infra.apiLog', 'id')" min-width="120">
        {{ detailData.id }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'traceId')">
        {{ detailData.traceId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'applicationName')">
        {{ detailData.applicationName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'userInfo')">
        {{ detailData.userId }}
        <dict-tag :type="DICT_TYPE.USER_TYPE" :value="detailData.userType" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'userIp')">
        {{ detailData.userIp }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'userAgent')">
        {{ detailData.userAgent }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'requestInfo')">
        <el-tag>{{ detailData.requestMethod }}</el-tag>
        {{ detailData.requestUrl }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog', 'requestParams')">
        {{ detailData.requestParams }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog.error', 'exceptionTime')">
        {{ formatDate(detailData.exceptionTime) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog.error', 'exceptionName')">
        {{ detailData.exceptionName }}
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.exceptionStackTrace" :label="t('infra.apiLog.error', 'exceptionStackTrace')">
        <el-input v-model="detailData.exceptionStackTrace" :autosize="{ maxRows: 20 }" :readonly="true" type="textarea" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.apiLog.error', 'processStatus')">
        <dict-tag :type="DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS" :value="detailData.processStatus" />
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.processUserId" :label="t('infra.apiLog.error', 'processUser')">
        {{ detailData.processUserId }}
      </el-descriptions-item>
      <el-descriptions-item v-if="detailData.processTime" :label="t('infra.apiLog.error', 'processTime')">
        {{ formatDate(detailData.processTime) }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<style scoped lang="scss"></style>
